package com.tao.ormlib;

import com.j256.ormlite.dao.CloseableIterator;
import com.j256.ormlite.dao.CloseableWrappedIterable;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.dao.DatabaseResultsMapper;
import com.j256.ormlite.dao.ForeignCollection;
import com.j256.ormlite.dao.GenericRawResults;
import com.j256.ormlite.dao.ObjectCache;
import com.j256.ormlite.dao.RawRowMapper;
import com.j256.ormlite.dao.RawRowObjectMapper;
import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.FieldType;
import com.j256.ormlite.stmt.DeleteBuilder;
import com.j256.ormlite.stmt.GenericRowMapper;
import com.j256.ormlite.stmt.PreparedDelete;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.PreparedUpdate;
import com.j256.ormlite.stmt.QueryBuilder;
import com.j256.ormlite.stmt.UpdateBuilder;
import com.j256.ormlite.support.ConnectionSource;
import com.j256.ormlite.support.DatabaseConnection;
import com.j256.ormlite.support.DatabaseResults;
import com.j256.ormlite.table.ObjectFactory;
import com.j256.ormlite.table.TableInfo;

import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;

public class DaoProxy implements Dao {


    Dao dao;

    public DaoProxy(Dao dao) throws Exception {
        synchronized (dao) {
            if (null == dao)
                throw new Exception(" set dao will be not  null");
            this.dao = dao;
        }
    }

    @Override
    public Object queryForId(Object o) throws SQLException {

        synchronized (dao) {
            return dao.queryForId(o);
        }
    }

    @Override
    public Object queryForFirst(PreparedQuery preparedQuery) throws SQLException {
        synchronized (dao) {
            return dao.queryForFirst(preparedQuery);
        }
    }

    @Override
    public List queryForAll() throws SQLException {
        synchronized (dao) {
            return dao.queryForAll();
        }
    }

    @Override
    public List queryForEq(String s, Object o) throws SQLException {
        synchronized (dao) {
            return dao.queryForEq(s, o);
        }
    }

    @Override
    public List queryForMatching(Object o) throws SQLException {
        synchronized (dao) {
            return dao.queryForMatching(o);
        }
    }

    @Override
    public List queryForMatchingArgs(Object o) throws SQLException {
        synchronized (dao) {
            return dao.queryForMatchingArgs(o);
        }
    }

    @Override
    public Object queryForSameId(Object o) throws SQLException {
        synchronized (dao) {
            return dao.queryForSameId(o);
        }
    }

    @Override
    public QueryBuilder queryBuilder() {
        synchronized (dao) {
            return dao.queryBuilder();
        }
    }

    @Override
    public UpdateBuilder updateBuilder() {
        synchronized (dao) {
            return dao.updateBuilder();
        }
    }

    @Override
    public DeleteBuilder deleteBuilder() {
        synchronized (dao) {
            return dao.deleteBuilder();
        }
    }

    @Override
    public List query(PreparedQuery preparedQuery) throws SQLException {
        synchronized (dao) {
            return dao.query(preparedQuery);
        }
    }

    @Override
    public int create(Object o) throws SQLException {
        synchronized (dao) {
            return dao.create(o);
        }
    }

    @Override
    public int create(Collection collection) throws SQLException {
        synchronized (dao) {
            return dao.create(collection);
        }
    }

    @Override
    public Object createIfNotExists(Object o) throws SQLException {
        synchronized (dao) {
            return dao.createIfNotExists(o);
        }
    }

    @Override
    public CreateOrUpdateStatus createOrUpdate(Object o) throws SQLException {
        synchronized (dao) {
            return dao.createOrUpdate(o);
        }
    }

    @Override
    public int update(Object o) throws SQLException {
        synchronized (dao) {
            return dao.update(o);
        }
    }

    @Override
    public int updateId(Object o, Object o2) throws SQLException {
        synchronized (dao) {
            return dao.updateId(o, o2);
        }
    }

    @Override
    public int update(PreparedUpdate preparedUpdate) throws SQLException {
        synchronized (dao) {
            return dao.update(preparedUpdate);
        }
    }

    @Override
    public int refresh(Object o) throws SQLException {
        synchronized (dao) {
            return dao.refresh(o);
        }
    }

    @Override
    public int delete(Object o) throws SQLException {
        synchronized (dao) {
            return dao.delete(o);
        }
    }

    @Override
    public int deleteById(Object o) throws SQLException {
        synchronized (dao) {
            return dao.deleteById(o);
        }
    }

    @Override
    public int delete(Collection collection) throws SQLException {
        synchronized (dao) {
            return dao.delete(collection);
        }
    }

    @Override
    public int deleteIds(Collection collection) throws SQLException {
        synchronized (dao) {
            return dao.deleteIds(collection);
        }
    }

    @Override
    public int delete(PreparedDelete preparedDelete) throws SQLException {
        synchronized (dao) {
            return dao.delete(preparedDelete);
        }
    }

    @Override
    public CloseableIterator iterator() {
        synchronized (dao) {
            return dao.iterator();
        }
    }

    @Override
    public CloseableIterator iterator(int i) {
        synchronized (dao) {
            return dao.iterator(i);
        }
    }

    @Override
    public CloseableIterator iterator(PreparedQuery preparedQuery) throws SQLException {
        synchronized (dao) {
            return dao.iterator(preparedQuery);
        }
    }

    @Override
    public CloseableIterator iterator(PreparedQuery preparedQuery, int i) throws SQLException {
        synchronized (dao) {
            return dao.iterator(preparedQuery, i);
        }
    }

    @Override
    public CloseableWrappedIterable getWrappedIterable() {
        synchronized (dao) {

            return dao.getWrappedIterable();
        }
    }

    @Override
    public CloseableWrappedIterable getWrappedIterable(PreparedQuery preparedQuery) {

        return dao.getWrappedIterable(preparedQuery);
    }

    @Override
    public void closeLastIterator() throws IOException {
        synchronized (dao) {
            dao.closeLastIterator();
        }
    }

    @Override
    public GenericRawResults<String[]> queryRaw(String s, String... strings) throws SQLException {
        synchronized (dao) {
            return dao.queryRaw(s, strings);
        }
    }

    @Override
    public GenericRawResults<Object[]> queryRaw(String s, DataType[] dataTypes, String... strings) throws SQLException {
        synchronized (dao) {
            return dao.queryRaw(s, dataTypes, strings);
        }
    }

    @Override
    public long queryRawValue(String s, String... strings) throws SQLException {
        synchronized (dao) {
            return dao.queryRawValue(s, strings);
        }
    }

    @Override
    public int executeRaw(String s, String... strings) throws SQLException {
        synchronized (dao) {
            return dao.executeRaw(s, strings);
        }
    }

    @Override
    public int executeRawNoArgs(String s) throws SQLException {
        synchronized (dao) {
            return dao.executeRawNoArgs(s);
        }
    }

    @Override
    public int updateRaw(String s, String... strings) throws SQLException {
        synchronized (dao) {
            return dao.updateRaw(s, strings);
        }
    }

    @Override
    public String objectToString(Object o) {
        synchronized (dao) {
            return dao.objectToString(o);
        }
    }

    @Override
    public boolean objectsEqual(Object o, Object t1) throws SQLException {
        synchronized (dao) {
            return dao.objectsEqual(o, t1);
        }
    }

    @Override
    public Object extractId(Object o) throws SQLException {
        synchronized (dao) {
            return dao.extractId(o);
        }
    }

    @Override
    public Class getDataClass() {

        return dao.getDataClass();

    }

    @Override
    public boolean isUpdatable() {
        synchronized (dao) {
            return dao.isUpdatable();
        }
    }

    @Override
    public boolean isTableExists() throws SQLException {
        synchronized (dao) {
            return dao.isTableExists();
        }
    }

    @Override
    public long countOf() throws SQLException {
        synchronized (dao) {
            return dao.countOf();
        }
    }

    @Override
    public long countOf(PreparedQuery preparedQuery) throws SQLException {
        synchronized (dao) {
            return dao.countOf(preparedQuery);
        }
    }

    @Override
    public void assignEmptyForeignCollection(Object o, String s) throws SQLException {
        synchronized (dao) {
            dao.assignEmptyForeignCollection(o, s);
        }
    }

    @Override
    public void setObjectCache(boolean b) throws SQLException {
        synchronized (dao) {
            dao.setObjectCache(b);
        }
    }

    @Override
    public void setObjectCache(ObjectCache objectCache) throws SQLException {
        synchronized (dao) {
            dao.setObjectCache(objectCache);
        }
    }

    @Override
    public ObjectCache getObjectCache() {
        synchronized (dao) {

            return dao.getObjectCache();
        }
    }

    @Override
    public void clearObjectCache() {
        synchronized (dao) {
            dao.clearObjectCache();
        }
    }

    @Override
    public Object mapSelectStarRow(DatabaseResults databaseResults) throws SQLException {
        synchronized (dao) {
            return dao.mapSelectStarRow(databaseResults);
        }
    }

    @Override
    public GenericRowMapper getSelectStarRowMapper() throws SQLException {
        synchronized (dao) {

            return dao.getSelectStarRowMapper();
        }
    }

    @Override
    public RawRowMapper getRawRowMapper() {
        synchronized (dao) {

            return dao.getRawRowMapper();
        }
    }

    @Override
    public boolean idExists(Object o) throws SQLException {
        synchronized (dao) {
            return dao.idExists(o);
        }
    }

    @Override
    public DatabaseConnection startThreadConnection() throws SQLException {
        return dao.startThreadConnection();
    }

    @Override
    public void endThreadConnection(DatabaseConnection databaseConnection) throws SQLException {
        dao.endThreadConnection(databaseConnection);
    }

    @Override
    public void setAutoCommit(DatabaseConnection databaseConnection, boolean b) throws SQLException {
        synchronized (dao) {
            dao.setAutoCommit(databaseConnection, b);
        }
    }

    @Override
    public boolean isAutoCommit(DatabaseConnection databaseConnection) throws SQLException {
        synchronized (dao) {
            return dao.isAutoCommit(databaseConnection);
        }
    }

    @Override
    public void commit(DatabaseConnection databaseConnection) throws SQLException {
        synchronized (dao) {
            dao.commit(databaseConnection);
        }
    }

    @Override
    public void rollBack(DatabaseConnection databaseConnection) throws SQLException {
        synchronized (dao) {
            dao.rollBack(databaseConnection);
        }
    }

    @Override
    public ConnectionSource getConnectionSource() {
        synchronized (dao) {
            return dao.getConnectionSource();
        }
    }

    @Override
    public void setObjectFactory(ObjectFactory objectFactory) {
        synchronized (dao) {
            dao.setObjectFactory(objectFactory);
        }
    }

    @Override
    public void registerObserver(DaoObserver daoObserver) {
        synchronized (dao) {
            dao.registerObserver(daoObserver);
        }
    }

    @Override
    public void unregisterObserver(DaoObserver daoObserver) {
        synchronized (dao) {
            dao.unregisterObserver(daoObserver);
        }
    }

    @Override
    public String getTableName() {
        synchronized (dao) {
            return dao.getTableName();
        }
    }

    @Override
    public void notifyChanges() {
        synchronized (dao) {
            dao.notifyChanges();
        }
    }

    @Override
    public Object createObjectInstance() throws SQLException {
        synchronized (dao) {
            return dao.createObjectInstance();
        }
    }

    @Override
    public TableInfo getTableInfo() {
        synchronized (dao) {

            return dao.getTableInfo();
        }
    }

    @Override
    public ForeignCollection getEmptyForeignCollection(String s) throws SQLException {
        synchronized (dao) {
            return dao.getEmptyForeignCollection(s);
        }
    }

    @Override
    public FieldType findForeignFieldType(Class aClass) {
        synchronized (dao) {
            return dao.findForeignFieldType(aClass);
        }
    }

    @Override
    public Object callBatchTasks(Callable callable) throws Exception {
        synchronized (dao) {
            return dao.callBatchTasks(callable);
        }
    }

    @Override
    public GenericRawResults queryRaw(String s, DatabaseResultsMapper databaseResultsMapper, String... strings) throws SQLException {
        synchronized (dao) {
            return dao.queryRaw(s, databaseResultsMapper, strings);
        }
    }

    @Override
    public GenericRawResults queryRaw(String s, DataType[] dataTypes, RawRowObjectMapper rawRowObjectMapper, String... strings) throws SQLException {
        synchronized (dao) {
            return dao.queryRaw(s, dataTypes, rawRowObjectMapper, strings);
        }
    }

    @Override
    public GenericRawResults queryRaw(String s, RawRowMapper rawRowMapper, String... strings) throws SQLException {
        synchronized (dao) {
            return dao.queryRaw(s, rawRowMapper, strings);
        }
    }

    @Override
    public List queryForFieldValuesArgs(Map map) throws SQLException {
        synchronized (dao) {
            return dao.queryForFieldValuesArgs(map);
        }
    }

    @Override
    public List queryForFieldValues(Map map) throws SQLException {
        synchronized (dao) {
            return dao.queryForFieldValues(map);
        }
    }

    @Override
    public CloseableIterator closeableIterator() {
        synchronized (dao) {
            return dao.closeableIterator();
        }
    }
}
